package com.zjbti.album;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.recyclerview.widget.RecyclerView;



public class AlbumAdapter extends RecyclerView.Adapter<AlbumAdapter.ViewHolder> {
    private Context context;
    private int[] photos;
    public AlbumAdapter(Context context,int[] photos) {
        this.context = context;
        this.photos=photos;
    }
    @Override
    public AlbumAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView= LayoutInflater.from(context).inflate(
                R.layout.list_item,parent,false);
        return new ViewHolder(itemView);
    }
    @Override
    public void onBindViewHolder( AlbumAdapter.ViewHolder holder, int position) {
        holder.iv_img.setImageResource(photos[position]);
    }
    @Override
    public int getItemCount() {
        return photos==null?0:photos.length;
    }
    class ViewHolder extends RecyclerView.ViewHolder{
        private ImageView iv_img;
        public ViewHolder(View itemView) {
            super(itemView);
            iv_img = itemView.findViewById(R.id.iv_img);
        }
    }
}

